package com.example.template;

import com.example.constant.MQConstant;
import com.example.po.SysMQMessage;
import com.example.service.SysMQMessageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SysMQTemplateImpl implements SysMQTemplate {

    @Resource
    private SysMQMessageService sysMQMessageService;

    /***
     * 保存mq发送信息
     * @param type
     * @param name
     * @param message
     * @return
     */
    @Override
    public SysMQMessage send(String type, String name, String message) {
        SysMQMessage sysMQMessage = new SysMQMessage();
        sysMQMessage.setType(type);
        sysMQMessage.setName(name);
        sysMQMessage.setContent(message);
        sysMQMessage.setStatus(MQConstant.INIT);
        sysMQMessage.setRetryCount(0);
        sysMQMessage.recalculateFields();
        sysMQMessageService.save(sysMQMessage);
        return sysMQMessage;
    }
}
